package com.jl.core.common;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
@EnableWebMvc
public class InterceptionConfig implements WebMvcConfigurer {

    @Resource
    private MyInterception myInterception;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

//        String[] excludePath = {"/authentication/**","/swagger-resources/**","/webjars/**","/v2/**","/swagger-ui.html/**","/error","/csrf"};
        String[] intercept = {"/coalition/**","/user/**","/proxy/**","/game/**"};
        String[] exclude = {"/proxy/download","/coalition/review"};

        registry.addInterceptor(myInterception).addPathPatterns(intercept).excludePathPatterns(exclude);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/photo/**").addResourceLocations("file:/root/photo/");

        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/");

        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
}
